home *** CD-ROM | disk | FTP | other *** search
/ Windows Expert / Windows Expert.iso / utility / wzun11sr.zip / KBDPROC.C < prev    next >
C/C++ Source or Header  |  1991-11-11  |  2KB  |  72 lines

  1. #include <windows.h>
  2. #include "wizunzip.h"
  3.  
  4. /* Keyboard procedure used to sub-class all windows which can be
  5.  * tab stops.
  6.  */
  7.  
  8. extern char szHelpFileName[];    /* in wndproc.c                    */
  9.  
  10. /* Keyboard procedure
  11.  * This function allows the user to tab and back-tab among the 
  12.  * listbox, four command buttons,and message window.  
  13.  * It traps VK_TAB messages and sets the
  14.  * focus on the next or previous window as required.
  15.  * Skip any disabled buttons.
  16.  */
  17. long FAR PASCAL KbdProc(HWND hWnd, WORD message, WORD wParam, LONG lParam)
  18. {
  19. int nID = GetWindowWord(hWnd, GWW_ID); /* child window ID no.        */
  20. int nTabStopTableIndex = nID - TABSTOP_ID_BASE;
  21. int nNextTabStopTableIndex = nTabStopTableIndex;
  22.  
  23.     switch (message) {
  24.     case WM_KEYDOWN:
  25.         if (wParam == VK_TAB)
  26.         {
  27.         int nRelIndex = /* forward or backward ?                     */
  28.                     (int)(GetKeyState(VK_SHIFT) < 0 ? -1 : 1);
  29.  
  30.             do {
  31.                 nNextTabStopTableIndex += nRelIndex;
  32.                 if (nNextTabStopTableIndex < 0)
  33.                     nNextTabStopTableIndex = TABSTOP_TABLE_ENTRIES-1;
  34.  
  35.                 else if (nNextTabStopTableIndex >= TABSTOP_TABLE_ENTRIES)
  36.                     nNextTabStopTableIndex = 0;
  37.             
  38.             }
  39.             while (!IsWindowEnabled(TabStopTable[nNextTabStopTableIndex].hWnd));
  40.  
  41.             SetFocus(TabStopTable[nNextTabStopTableIndex].hWnd);
  42.  
  43.         }
  44.         else if (wParam == VK_F1) {
  45.  
  46.                /* If Shift-F1, turn help mode on and set help cursor */ 
  47.  
  48.                if (GetKeyState(VK_SHIFT)<0) {
  49.                    bHelp = TRUE;
  50.                    SetCursor(hHelpCursor);
  51.                    return (CallWindowProc(TabStopTable[nTabStopTableIndex].lpfnOldFunc,
  52.                             hWnd, message, wParam, lParam));
  53.                }
  54.  
  55.                /* If F1 without shift, then call up help main index topic */ 
  56.                else {
  57.                    WinHelp(hMainWnd,szHelpFileName,HELP_INDEX,0L);
  58.                }
  59.            }
  60.  
  61.         else if (wParam == VK_ESCAPE && bHelp) {
  62.  
  63.                /* Escape during help mode: turn help mode off */
  64.                bHelp = FALSE;
  65.                SetCursor((HCURSOR)GetClassWord(hMainWnd,GCW_HCURSOR));
  66.         }
  67.         break;
  68.     }
  69.     return CallWindowProc(TabStopTable[nTabStopTableIndex].lpfnOldFunc,
  70.                             hWnd, message, wParam, lParam);
  71. }             
  72.